package app.imttf.offline.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class PasswordEncoder {

    public static String encodePassword(String password) {

        String encodedPass = null;
        try {

            byte[] passBytes = password.getBytes();

            MessageDigest sha1 = MessageDigest.getInstance("SHA1");
            sha1.update(passBytes);
            byte[] digestBytes = sha1.digest();
            BASE64Encoder b64Encoder = new BASE64Encoder();
            encodedPass = b64Encoder.encode(digestBytes);

        }

        catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return encodedPass;
    }
}
